﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using METU_CMT.Business;

namespace METU_CMT
{
    public partial class UpdateCourseScreen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindCourseInfo();
            }
        }

        public void BindCourseInfo()
        {
            CourseInstructor _courseInstructor = (CourseInstructor) EntityFactory.GetCurrentCourse(UserType.Instructor);
            SetCourseInfo(_courseInstructor);
        }

        private void SetCourseInfo(CourseInstructor courseInstructor)
        {
            txtCourseCode.Text = courseInstructor.CourseCode;
            txtCourseName.Text = courseInstructor.CourseName;
            txtSemester.Text = courseInstructor.Semester;
        }

        protected void OnBtnUpdateClicked(object sender, EventArgs e)
        {
            Instructor _instructor = (Instructor) EntityFactory.User;
            CourseInstructor _oldcourse = (CourseInstructor) EntityFactory.GetCurrentCourse(UserType.Instructor);
            CourseInstructor _newCourse = _oldcourse;
            _newCourse.CourseCode = txtCourseCode.Text;
            _newCourse.CourseName = txtCourseName.Text;
            _newCourse.Semester = txtSemester.Text;
            //There is comfliction with ta.
            _instructor.UpdateCourse(_newCourse);

            Response.Redirect( "~/InstructorCourseMainScreen.aspx" );

        }


    }
}